package com.wubotao.multithreading;

public class PrintNum {
    private byte[] lock = new byte[0];
 
    public void demo() {
        PrintThread a = new PrintThread("a");
        PrintThread b = new PrintThread("b");
        a.start();
        b.start();
    }
 
    class PrintThread extends Thread {
        public PrintThread(String name) {
            this.setName(name);
        }
 
        @Override
        public void run() {
            synchronized (lock) {
            	System.out.println(this);
 
                for (int i = 0; i < 100; i++) {
 
                    if (i % 10 == 0 && 0 != i) {
                        try {
                        	lock.notify();
                        	lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println(this.getName() + ": " + i);
                }
                lock.notify();
            }
        }
    }
 
    public static void main(String[] args) {
        PrintNum printNum = new PrintNum();
        printNum.demo();
    }
}
